﻿using System;
using System.Collections.Generic;
using System.Text;

namespace NVR.BLL
{
    public class UserInfo
    {
        private DALFactory.DALFactory dataFactory = DataProvider.DefaultProvider;
        public int 添加(Entity.userInfo obj)
        {
            return dataFactory.DALUserInfoProvider.Insert(obj);
        }

        public int Delete(string username)
        {
            Entity.userInfo userInfo = new Entity.userInfo();
            userInfo.username = username;
            return dataFactory.DALUserInfoProvider.Delete(userInfo);
        }
        /// <summary>
        /// 根据用户名和密码判断该用户是否在数据库中存在
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="pwd">密码</param>
        /// <returns>1：存在，0：不存在</returns>
        public int IsExist(string userName,string pwd)
        {
            Entity.userInfo user = dataFactory.DALUserInfoProvider.LoadById(userName);
            if (user==null)
            {
                return 0;
            } 
            else
            {
                if (user.pwd == pwd)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
        }

        /// <summary>
        /// 根据用户得到用户类型，1：超级管理员，2：管理员，3：普通用户
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public string GetUserType(string username)
        {
            Entity.userInfo user=dataFactory.DALUserInfoProvider.LoadById(username);
            if (user.purview==1)
            {
                return "超级管理员";
            }
           /* else if (user.purview==2)
            {
                return "管理员";
            }*/
            else
            {
                return "普通用户";
            }
        }

        public Entity.userInfo GetUserInfo(string username)
        {
            return dataFactory.DALUserInfoProvider.LoadById(username);
        }

        public int UpdateUser(NVR.Entity.userInfo user)
        {
            return dataFactory.DALUserInfoProvider.Update(user);
        }
    }
}
